package com.winning.service;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.winning.config.MyRabbitMqConfig;
import com.winning.entity.Person;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@Service
@Slf4j
public class ProduceDeductService {
    @Autowired
    private RabbitTemplate oneRabbitTemplate;

    /*
        完美发送消息的方式(包含了ConfirmCallback和ReturnCallback需要的回调的参数)
     */
    public void perfectSendDirect(){
        String uuid = UUID.randomUUID().toString();
        CorrelationData cd = new CorrelationData(uuid);
        try {
            Person person = new Person();
            person.setName("lujieni");
            person.setSex("男");
            person.setAge(27);
            oneRabbitTemplate.convertAndSend("commonBusinessExchange", "deductBusinessRoutingKey", person, cd); // cd必要
        } catch (Exception e) {
            // mq被关闭或者网络中断都会被catch
            log.error("errpr:{}",e.getMessage());
        }
    }

}
